package com.adfframeworks.labs.controllers;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;

import com.adfframeworks.labs.service.CommunityMembersService;
import com.adfframeworks.labs.service.CommunityService;
import com.adfframeworks.labs.service.EmployeeService;
import com.adfframeworks.labs.service.RequestService;

@Controller
@RequestMapping("/welcome")
public class WelcomeController {

	@Autowired
	EmployeeService employeeService;
	
	@Autowired
	CommunityService communityService;
	
	@Autowired
	CommunityMembersService communityMembersService;
	
	@Autowired
	RequestService requestService;

	@RequestMapping(value = "/id={user_id}", method = RequestMethod.GET)
	public String displayHome(@PathVariable Integer user_id, ModelMap model) {
		model.addAttribute("user", employeeService.getEmployee(user_id));
		model.addAttribute("owner_communities", communityMembersService.listCommunitiesAsOwner(user_id));
		model.addAttribute("member_communities", communityMembersService.listCommunitiesAsNotOwner(user_id));
		model.addAttribute("latest_communities", communityService.listTenLastCommunities());
		
		model.addAttribute("requests", requestService.listAllToRequests(user_id));
		return "home";
	}
}
